package com.seecoder.BlueWhale.serviceImpl.calPriceStrategy;

/**
 * @Author: DingXiaoyu
 * @Date: 22:35 2023/12/19
 * “蓝鲸券”使用规则：
 * 0-100元区间打九五折；
 * 100-200元区间打九折；
 * 200-300元区间打八五折；
 * 300-400元区间打八折；
 * 400-500元区间打七五折；
 * 500元以上区间打七折。
*/
public class SpecialCouponCalculateStrategy implements CalculateStrategy {

    private final Double[] bracketTable = {0.0, 100.0, 200.0, 300.0, 400.0, 500.0};
    private final Double[] baseTable = {0.0, 95.0, 185.0, 270.0, 350.0, 425.0};
    private final Double[] discountTable = {0.95, 0.9, 0.85, 0.8, 0.75, 0.7};

    @Override
    public Double calculate(Double price) {
        int level = -1;
        for (Double aDouble : bracketTable) {
            if (price < aDouble) {
                break;
            }
            level++;
        }
        return baseTable[level] + (price - bracketTable[level]) * discountTable[level];
    }
}
